<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>物业公告</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="/WisdomHome/resource/weixin/css/mui.min.css">
	</head>

	<body>
		<!--下拉刷新容器-->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view mui-table-view-chevron">
					
				</ul>
			</div>
		</div>
		<form id="detailForm" action="/WisdomHome/weixin/announce_detail" method="post">
    		<input id="announceId" name="announceId" type="hidden">
 		</form>
		<script src="/WisdomHome/resource/weixin/js/mui.min.js"></script>
		<script src="/WisdomHome/resource/assets/js/jquery-2.0.3.min.js"></script>
		<script src="/WisdomHome/resource/assets/js/jquery.cookie.js"></script>
		<script>
		var currentPage = 0;
		var userId = $.cookie("userId");
		function unixToDate(unixTime, isFull, timeZone) {
		    if (typeof (timeZone) == 'number')
		    {
		        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
		    }
		    var time = new Date(parseInt(unixTime));
		    var ymdhis = "";
		    ymdhis += time.getFullYear() + "/";
		    ymdhis += (time.getMonth()+1) + "/";
		    ymdhis += time.getDate();
		    if (isFull === true)
		    {
		        ymdhis += " " + time.getHours() + ":";
		        ymdhis += time.getMinutes() + ":";
		        ymdhis += time.getSeconds();
		    }
		    return ymdhis;
		}
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			
			function pullupRefresh() {
				currentPage++;
				$.ajax({
					url:'/WisdomHome/weixin/announce_more',
					type:'post',
					dataType:'json',
					data:{
						userId:userId,
						pageIndex:currentPage
					},
					success:function(data){
						if (data == 205) {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
							console.log("user is not exist!");
							return;
						}
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(!data.hasNextPage);
						var table = document.body.querySelector('.mui-table-view');
						var cells = document.body.querySelectorAll('.mui-table-view-cell');
						$.each(data.dataList,function(){
							var li = document.createElement('li');
							li.className = 'mui-table-view-cell';
							li.title = this.objectId;
							li.innerHTML = '<a class="mui-navigate-right">'+this.subject+' <span style="font-size:14px;float:right;color:#767676">'+unixToDate(this.updateAt,false)+'</span></a>';
							li.addEventListener('tap',showDetail);
							table.appendChild(li);
						});
					},
					error:function(data){
						
					}
				});
			}
			if (mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 1000);

				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
			
			function showDetail(){
				$("#announceId").val(this.title);
				$("#detailForm").submit();
			}
		</script>
	</body>

</html>